import resolve from "rollup-plugin-node-resolve";
import rollupTypescript from "rollup-plugin-typescript2";
import babel from "rollup-plugin-babel";
import path from "path";
import commonjs from "rollup-plugin-commonjs";
import postcss from "rollup-plugin-postcss";

export default {
  input: "src/rollup.ts",
  output: {
    file: "rollup/index.js",
    format: "esm",
  },
  plugins: [
    resolve({
      extensions: [".js", ".ts", ".tsx"],
      modulesOnly: true, // 只关注模块化（true的时候不会打包react这样的源代码进去）
    }),
    commonjs(),
    postcss({
      // extract: true, // true将css抽离出来但是使用的时候要重新引入css，false直接将css打包到js文件中
      // extensions: [".css", ".less"],
    }),
    rollupTypescript({
      tsconfig: path.resolve(__dirname, "./tsconfig.json"),
      tsconfigOverride: { compilerOptions: { module: "ESNext" } }, // 优先级最高的ts配置
      tsconfigDefaults: {}, // 默认ts配置
    }),
    babel({
      exclude: "node_modules/**/*",
      runtimeHelpers: true,
      extensions: [".js", ".ts", ".tsx"],
    }),
  ],
};
